﻿using System;

public class NeighbourElementsComparison
{
    static void Main()
    {
        int[] array = { 2, 6, 1, 2, -4, 16, 15, 20, 18, 0, 9, 1 };

        // Printing the array on the console
        for (int i = 0; i < array.Length; i++)
        {
            Console.WriteLine("[{0,2}] = {1,2}", i, array[i]);
        }

        Console.WriteLine();
        
        int numPosition = 1;

        if (CompareNeighbourElement(array, numPosition) > -1)
        {
            Console.WriteLine("[{0}] = {1} is bigger than its neighbours!", numPosition, array[numPosition]);
        }
        else
        {
            Console.WriteLine("[{0}] = {1} is smaller than its neighbours!", numPosition, array[numPosition]);
        }
    }

    public static int CompareNeighbourElement(int[] array, int index)
    {
        if (index == 0)
        {
            if (array[index] > array[index + 1])
            {
                return index;
            }
            else
            {
                return -1;
            }
        }

        if (index == array.Length - 1)
        {
            if (array[index] > array[index - 1])
            {
                return index;
            }
            else
            {
                return -1;
            }
        }

        if (array[index] > array[index - 1] && array[index] > array[index + 1])
        {
            return index;
        }

        return -1;
    }
}
